package com.example.yuan0603;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.yml.R;

public class ReceiverActivity extends AppCompatActivity implements View.OnClickListener {
    private Button butt;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.acticity_receiver);
        initView();
        initReceiver();
    }

    public void initReceiver(){
        Dt dt=new Dt();
        IntentFilter intentFilter=new IntentFilter();
        intentFilter.addAction("com.example.yuan0603.ReceiverActivity");
        registerReceiver(dt,intentFilter);
    }

    private void initView() {
        butt = (Button) findViewById(R.id.butt);

        butt.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.butt:
                boolean b=true;
                Intent intent = new Intent();
                intent.setAction("com.example.yuan0603.ReceiverActivity");
                intent.putExtra("myData",b );
                sendBroadcast(intent);
                Log.e("onClick: ", "se");
                break;
        }
    }
}
class Dt extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

    }
}


